package com.systop.ltbook.sms.statistics.webapp;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.systop.common.modules.security.user.LoginUserService;
import com.systop.common.modules.security.user.model.User;
import com.systop.core.webapp.struts2.action.ExtJsCrudAction;
import com.systop.ltbook.sms.model.SmsSend;
import com.systop.ltbook.sms.statistics.service.SmsStatisticsManager;

/**
 * 短息统计的struts2 Action。
 * 
 * @author DU
 * 
 */
@SuppressWarnings( { "serial", "unchecked" })
@Controller
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class SmsStatisticsAction extends ExtJsCrudAction<SmsSend, SmsStatisticsManager>{

	/** 查询起始时间 */
	private Date beginDate;
	
	/** 查询结束时间 */
	private Date endDate;
	
	/** 统计结果 */
	private List<Map> rstList;
	
	@Autowired
	private LoginUserService loginUserService;
	
	/**
	 * 个人发送短信统计
	 */
	public String statByPersonal() {
		User loginUser = loginUserService.getLoginUser(getRequest());
		if (loginUser != null) {
			rstList = getManager().statistics(beginDate, endDate, loginUser);
		}
		
		return "personal";
	}

	/**
	 * 统计所有已发送的短信
	 */
	public String statByAll() {
		rstList = getManager().statistics(beginDate, endDate, null);
		
		return "all";
	}
	
	public List<Map> getRstList() {
  	return rstList;
  }

	public void setRstList(List<Map> rstList) {
  	this.rstList = rstList;
  }

	public Date getBeginDate() {
  	return beginDate;
  }

	public void setBeginDate(Date beginDate) {
  	this.beginDate = beginDate;
  }

	public Date getEndDate() {
  	return endDate;
  }

	public void setEndDate(Date endDate) {
  	this.endDate = endDate;
  }
}
